<template>
  <div class="container">
    <el-dialog
      title="试题预览"
      :visible="showQuestionsDialog"
      width="60%"
      @close="close"
      @open="open"
    >
      <el-row>
        <el-col :span="6">【题型】:{{ questionType }}</el-col>
        <el-col :span="6">【编号】:{{ question.id }}</el-col>
        <el-col :span="6">【难度】:{{ difficulty }}</el-col>
        <el-col :span="6">【标签】:{{ question.tags }}</el-col>
      </el-row>
      <el-row style="margin-top:10px;">
        <el-col :span="6">【学科】:{{ question.subjectName }}</el-col>
        <el-col :span="6">【目录】:{{ question.directoryName }}</el-col>
        <el-col :span="6">【方向】:{{ question.direction }}</el-col>
      </el-row>
      <div class="divider" />
      <div>【题干】:</div>
      <div v-html="question.question" />
      <div v-if="questionType!=='简答' ">{{ questionType }} 选项：（以下选中的选项为正确答案）</div>
      <div v-for="item in options" v-show="questionType!=='简答' " :key="item.id" style="margin-top:10px;text-align:left;">
        {{ item.code }}
        <el-radio
          v-if="questionType==='单选'"
          v-model="radio"
          :label="item.isRight"
          style="margin-left:5px"
          :disabled="item.isRight===0"
        >{{ item.title }}</el-radio>
        <el-checkbox
          v-else-if="questionType==='多选'"
          v-model="checkList"
          :label="item.isRight"
          :disabled="item.isRight===0"
        >{{ item.title }}</el-checkbox>
      </div>
      <div class="divider" />
      <div>【参考答案】:<el-button type="danger" size="small" @click="isShowVideo">视频答案预览</el-button></div>
      <div v-show="showVideo" class="video">
        <video ref="video" :src="question.videoURL" controls />
      </div>
      <div class="divider" />
      【答案解析】: <span style="display:inline-block" v-html="question.answer" />
      <div class="divider" />
      【题目备注】:{{ question.remarks }}
      <el-row type="flex" justify="center">
        <el-button type="primary" @click="close">关闭</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { detail } from '@/api/hmmm/questions'
export default {
  name: 'QuestionsPreview',
  props: {
    showQuestionsDialog: {
      type: Boolean,
      required: true
    },
    questions: {
      type: Object,
      required: true
    },
    questionTypeList: {
      type: Array,
      required: true
    },
    difficultyList: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      questionType: '', // 题型
      difficulty: '', // 难度
      radio: 1,
      options: [],
      checkList: [1],
      showVideo: false,
      question: {}
    }
  },

  methods: {
    close() {
      this.$emit('update:showQuestionsDialog', false)
      this.showVideo = false
    },
    async open() {
      // 获取题库详情
      const data = await detail({ id: this.questions.id })
      console.log(data)
      console.log(data.data)
      this.question = data.data
      this.options = data.data.options
      // 题型
      this.questionType = this.questionTypeList.find(item => +item.value === +this.question.questionType).label
      // 难度
      this.difficulty = this.difficultyList.find(item => +item.value === +this.question.difficulty).label
    },
    isShowVideo() {
      this.showVideo = true
      this.$refs.video.play()
    }
  }
}
</script>

<style scoped lang='scss'>
.divider {
  width: 100%;
  height: 0.2px;
  background-color: #9b9b9b;
  margin: 20px 0;
}
.video {
  margin-top: 10px;
  width: 400px;
  height: 300px;
  video {
    width: 100%;
    height: 100%;
  }
}
</style>
